package com.vietnam.power.persitence;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.vietnam.power.domain.Root;

/**
 * The persistent class for the message_info database table.
 * 
 */
@Entity
@Table(name = "message_info")
public class MessageInfo implements Serializable, Root {
	private static final long serialVersionUID = 1L;
	private int id;
	private String content;
	private Date createdDate;
	private boolean status;
	private String subject;
	private List<EmailNotification> emailNotifications;
	private MessageTypeDictionary messageTypeDictionary;
	private String from;
	private String to;
	private String cc;

	public MessageInfo() {
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Lob
	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "created_date")
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public boolean getStatus() {
		return this.status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	@Column(name = "subject")
	public String getSubject() {
		return this.subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	@Column(name = "cc")
	public String getCc() {
		return cc;
	}

	public void setCc(String cc) {
		this.cc = cc;
	}

	// bi-directional many-to-one association to EmailNotification
	@OneToMany(mappedBy = "messageInfo", cascade = CascadeType.ALL, orphanRemoval = true)
	public List<EmailNotification> getEmailNotifications() {
		if (this.emailNotifications == null) {
			this.emailNotifications = new ArrayList<EmailNotification>();
		}
		return this.emailNotifications;
	}

	public void setEmailNotifications(List<EmailNotification> emailNotifications) {
		this.emailNotifications = emailNotifications;
	}

	public EmailNotification addEmailNotification(EmailNotification emailNotification) {
		getEmailNotifications().add(emailNotification);
		emailNotification.setMessageInfo(this);

		return emailNotification;
	}

	public EmailNotification removeEmailNotification(EmailNotification emailNotification) {
		getEmailNotifications().remove(emailNotification);
		emailNotification.setMessageInfo(null);

		return emailNotification;
	}

	// bi-directional many-to-one association to MessageTypeDictionary
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "message_type_id")
	public MessageTypeDictionary getMessageTypeDictionary() {
		return this.messageTypeDictionary;
	}

	public void setMessageTypeDictionary(MessageTypeDictionary messageTypeDictionary) {
		this.messageTypeDictionary = messageTypeDictionary;
	}

	@Column(name = "from_id")
	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	@Column(name = "to_id")
	public String getTo() {
		return to;
	}

	public void setTo(String to) {
		this.to = to;
	}

}